#include <iostream>
#include <cmath>
#include <string>
#include <unordered_map>

bool isPrime(int a) {
    for (int b = 2; b <= int(sqrt(a)) + 1; b++) {
        if (a % b == 0) {
            return false;
        }
    }
    return true;
}

std::unordered_map<std::string, int> digits = {
    {"zero", 0},
    {"one", 1},
    {"two", 2},
    {"three", 3},
    {"four", 4},
    {"five", 5},
    {"six", 6},
    {"seven", 7},
    {"eight", 8},
    {"nine", 9}
};

int main() {
    std::string input;
    std::getline(std::cin, input);

    std::vector<std::string> n;
    std::string word = "";
    for (char c : input) {
        if (c == ' ') {
            n.push_back(word);
            word = "";
        } else {
            word += c;
        }
    }
    n.push_back(word);

    std::string r = "";
    int j = 0;
    int k = 0;

    for (std::string i : n) {
        if (digits.find(i) != digits.end()) {
            r += std::to_string(digits[i]);
        } else {
            std::cout << "Wrong input" << std::endl;
            return 0;
        }
    }

    int num = std::stoi(r);

    for (int l = num; l < num * 1000; l++) {
        if (isPrime(l)) {
            j = l;
            break;
        }
    }

    for (int z = num; z > 2; z--) {
        if (isPrime(z)) {
            k = z;
            break;
        }
    }

    if (num - k > j - num) {
        std::cout << j << std::endl;
    } else {
        std::cout << k << std::endl;
    }

    return 0;
}
